package com.inspur.gs.sbssdl.sbwhgl.gyjgl.gyjgl.back.bizactions;
import com.inspur.edp.bef.api.lcp.ILcpFactory;
import com.inspur.edp.bef.api.lcp.IStandardLcp;
import com.inspur.edp.bef.api.services.IBefSessionManager;
import com.inspur.edp.cef.api.message.*;
import com.inspur.edp.bef.api.action.determination.*;
import com.inspur.edp.bef.api.action.validation.*;
import com.inspur.edp.cef.entity.changeset.*;
import com.inspur.edp.bef.api.be.*;
import com.inspur.edp.bef.api.action.VoidActionResult;
import com.inspur.edp.bef.spi.action.AbstractManagerAction;
import com.inspur.edp.cef.entity.entity.IEntityData;
import com.inspur.edp.cef.entity.entity.IEntityDataCollection;
import com.inspur.edp.cef.entity.entity.IValuesContainer;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;

import java.util.List;
import java.util.stream.Collectors;

public class gyjlysqsqWriteBackMgrAction extends AbstractManagerAction<VoidActionResult> {
	private String dataid;
	private String jlz;
	public gyjlysqsqWriteBackMgrAction(IBEManagerContext managerContext, String dataid, String jlz) {
		super(managerContext);
		this.dataid = dataid;
		this.jlz = jlz;
	}
	@Override
	public  void execute() {
		if (jlz.equals("Back")){
			return;
		}
		SpringBeanUtils.getBean(IBefSessionManager.class).createSession();
		try {
			//点检配置变更
			ILcpFactory iLcpFactory = SpringBeanUtils.getBean(ILcpFactory.class);
			//申请id
			String gyjsqid = "07405736-2927-4204-bca3-f099630cac07";
			IStandardLcp gyjsqlcp = iLcpFactory.createLcpByBEId(gyjsqid);
			//台账id
			String gyjtzid = "46911fe3-0d25-4e16-9e9e-c93393525ced";
			IStandardLcp gyjtzlcp = iLcpFactory.createLcpByBEId(gyjtzid);

			IEntityDataCollection lymx = gyjsqlcp.retrieve(dataid).getData().getChilds().get("lymx");
			List<String> tzids = lymx.stream()
					.map(s->((IValuesContainer)s.getValue("tzid")).getValue("tzid").toString())
					.collect(Collectors.toList());

			for (String tzid : tzids) {
				ModifyChangeDetail curChange = new ModifyChangeDetail(tzid);
				curChange.getPropertyChanges().put("zt","1");
				gyjtzlcp.modify(curChange);
			}
			gyjtzlcp.save();
		} finally {
			SpringBeanUtils.getBean(IBefSessionManager.class).closeCurrentSession();
		}
	}
	private IBusinessEntity getEntity(String dataId) {
		return (IBusinessEntity)super.getBEManagerContext().getEntity(dataId);
	}	private IBEService getMgr() {
		return (IBEService)super.getBEManagerContext().getBEManager();
	}
}